USE [DSRSystem]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spGetIndicatorTemplateAnswerCategories]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spGetIndicatorTemplateAnswerCategories]
GO

CREATE PROCEDURE [dbo].[spGetIndicatorTemplateAnswerCategories]
AS
BEGIN
	SELECT	dbo.Indicators.IndicatorId, 
			dbo.Indicators.Number AS IndicatorNumber, 
			dbo.AnswerCategories.Code, 
			dbo.AnswerCategories.Text, 
			dbo.AnswerCategories.Score
	FROM	dbo.Indicators INNER JOIN
            dbo.IndicatorAnswerCategories ON dbo.Indicators.IndicatorId = dbo.IndicatorAnswerCategories.IndicatorId INNER JOIN
            dbo.AnswerCategories ON dbo.IndicatorAnswerCategories.AnswerCategoryId = dbo.AnswerCategories.AnswerCategoryId
	WHERE  (dbo.Indicators.Template = 1) AND (dbo.Indicators.IndicatorTypeId = 1)
	ORDER BY IndicatorNumber, dbo.AnswerCategories.Number
END
GO


